﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using Telerik.Web.UI;
using KPIS.GERP.GHRMS.BLL;
using KPIS.GERP.GHRMS.IBLL;
using KPIS.GERP.GHRMS.MODEL;
using KPIS.GERP.GHRMS.APP.Classes;


namespace KPIS.GERP.GHRMS.APP.App_UI.Forms
{
    public partial class MP_JobsiteCommands : System.Web.UI.Page
    {
        private SsMng ssMng = new SsMng();
        private ICommandBLL cmdBLL = new CommandBLL();

        private CommandInfo cmdInfo;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                LoadDataGrid();
            }
        }
        public void LoadDataGrid()
        {
            DataSet ds = cmdBLL.LoadCommands(SystemInfo._CmdJobSite, (int?)null, (int?)null, (int?)null);
            DataTable dt = ds.Tables[0];
            RadGrid1.DataSource = dt;

            //GridGroupByExpression g = new GridGroupByExpression(RadGrid1.Columns[9]);
            //RadGrid1.MasterTableView.GroupByExpressions.Add(g);

            RadGrid1.DataBind();
        }
        protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e)
        {
            cmdInfo = new CommandInfo();

            if (e.CommandName == "DeleteAll")
            {
                GridItem[] items = RadGrid1.MasterTableView.GetItems(GridItemType.CommandItem);
                if (items.Length > 0)
                {
                    ((GridCommandItem)items[0]).FireCommandEvent("DeleteSelected", "");
                }
                else
                {
                    RadGrid1.Items[0].FireCommandEvent("DeleteSelected", "");
                }
            }
            else if (e.CommandName == "Delete")
            {
                string Seq = (e.Item as GridDataItem).OwnerTableView.DataKeyValues[e.Item.ItemIndex]["job_site_cmd_seq"].ToString();

                cmdBLL.Delete(SystemInfo._CmdJobSite, Int32.Parse(Seq), ssMng.EmpSeqI);
            }

            LoadDataGrid();

        }
    }
}
